from rest_framework import serializers

from MirrorCore.models.Collection import Collection


class CollectionSerializer(serializers.ModelSerializer):
    is_active = serializers.BooleanField(allow_null=True, required=False)

    class Meta:
        model = Collection
        fields = ['id', 'name', 'brief', 'content', 'input_script', 'collect_script', 'create_time', 'author',
                  'is_active']
        extra_kwargs = {
            'author': {'write_only': True},
            'content': {'write_only': True},
            'input_script': {'write_only': True},
            'collect_script': {'write_only': True}
        }

    def update(self, instance, validated_data):
        return super().update(instance, validated_data)

    def is_valid(self, raise_exception=False):
        return super().is_valid(raise_exception)

    def to_internal_value(self, data):
        test = super().to_internal_value(data)
        return test

    def validate(self, attrs):
        return super().validate(attrs)


class CollectionForOtherSerializer(serializers.ModelSerializer):
    """
        被引用的序列化程序
    """

    class Meta:
        model = Collection
        fields = ['id', 'name', 'brief', 'content', 'input_script', 'collect_script', 'create_time', 'author']
        extra_kwargs = {
            'author': {'write_only': True},
            'content': {'write_only': True},
            'input_script': {'write_only': True},
            'collect_script': {'write_only': True}
        }
